package com.polytech.diploma.DBTablesHelper;

import java.util.HashMap;
import java.util.Map;

import com.polytech.diploma.SQLGenerator.Oracle.Arguments.DataType;

public class DBTableFields {
	protected Map<String, DataTypeWithPrecision> tableFields = null;
	
	public class DataTypeWithPrecision
	{
		private DataType type = null;
		private int precision = 0;
		
		private DataTypeWithPrecision(DataType type, int precision) {
			super();
			this.type = type;
			this.precision = precision;
		}

		private DataType getType() {
			return type;
		}

		private int getPrecision() {
			return precision;
		}
	}

	public DBTableFields() {
		super();
		this.tableFields = new HashMap<String, DataTypeWithPrecision>();
	}
	
	public void addField(String field, String dataType, int precision)
	{
		DataTypeWithPrecision dataTypeWithPrecision = 
				new DataTypeWithPrecision(DataType.valueOf(dataType), precision);
		tableFields.put(field, dataTypeWithPrecision);
	}
	
	public void addField(String field, DataType dataType, int precision)
	{
		DataTypeWithPrecision dataTypeWithPrecision = 
				new DataTypeWithPrecision(dataType, precision);
		tableFields.put(field, dataTypeWithPrecision);
	}
	
	public boolean containsField(String field)
	{
		if(tableFields.containsKey(field))
			return true;
		else 
			return false;
	}
	
	public DataType getType (String field)
	{
		return tableFields.get(field).getType();
	}

	public int getPrecision(String field) {
		return tableFields.get(field).getPrecision();
	}
}
